package cc.idoone.spring_boot_hello.amqp.object;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @author hemj
 * @since 2017/10/15
 */
@Component
public class RabbitRunner implements CommandLineRunner {

	private final RabbitTemplate rabbitTemplate;

	@Autowired
	public RabbitRunner(RabbitTemplate rabbitTemplate) {
		this.rabbitTemplate = rabbitTemplate;
	}

	@Override
	public void run(String... args) throws Exception {
		System.out.println("Sending object...");
		UserObject userObject = new UserObject();
		userObject.setName("hemj");
		userObject.setAge(23);
		rabbitTemplate.convertAndSend(RabbitConfig.EXCHANGE, RabbitConfig.DIRECT_KEY, userObject);
	}

}
